#!/bin/bash
set -x 
SHELL_FOLDER=$(dirname $(readlink -f "$0"))
REGISTRY_URL="127.0.0.1:5000"

command -v docker >/dev/null 2>&1
if [ $? -ne 0 ]; then
    echo -e "\033[32m-> Install docker.\033[0m"
    curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
    systemctl restart docker.service
fi

echo -e "\033[32m-> Install registry.\033[0m"
docker rm -f registry >/dev/null 2>&1 || true
docker run -d --name registry \
-p 5000:5000 --restart always \
-v ${SHELL_FOLDER}/src/registry:/var/lib/registry \
registry:2.8.1


docker pull docker.io/minio/minio:RELEASE.2020-04-28T23-56-56Z
docker tag docker.io/minio/minio:RELEASE.2020-04-28T23-56-56Z ${REGISTRY_URL}/minio/minio:RELEASE.2020-04-28T23-56-56Z
docker push ${REGISTRY_URL}/minio/minio:RELEASE.2020-04-28T23-56-56Z

docker pull docker.io/nacos/nacos-mysql:5.7
docker tag docker.io/nacos/nacos-mysql:5.7 ${REGISTRY_URL}/nacos/nacos-mysql:5.7
docker push ${REGISTRY_URL}/nacos/nacos-mysql:5.7

docker pull docker.io/nacos/nacos-server:2.0.3
docker tag docker.io/nacos/nacos-server:2.0.3 ${REGISTRY_URL}/nacos/nacos-server:2.0.3
docker push ${REGISTRY_URL}/nacos/nacos-server:2.0.3

docker pull docker.io/library/redis:5.0.7
docker tag docker.io/library/redis:5.0.7 ${REGISTRY_URL}/library/redis:5.0.7
docker push ${REGISTRY_URL}/library/redis:5.0.7

docker pull docker.io/library/alpine:3.6
docker tag docker.io/library/alpine:3.6 ${REGISTRY_URL}/library/alpine:3.6
docker push ${REGISTRY_URL}/library/alpine:3.6

docker pull docker.elastic.co/kibana/kibana:7.17.16
docker tag docker.elastic.co/kibana/kibana:7.17.16 ${REGISTRY_URL}/kibana/kibana:7.17.16
docker push ${REGISTRY_URL}/kibana/kibana:7.17.16

docker pull docker.elastic.co/elasticsearch/elasticsearch:7.17.16
docker tag docker.elastic.co/elasticsearch/elasticsearch:7.17.16 ${REGISTRY_URL}/elasticsearch/elasticsearch:7.17.16
docker push ${REGISTRY_URL}/elasticsearch/elasticsearch:7.17.16

docker pull docker.io/fluent/fluent-bit:2.2.0
docker tag docker.io/fluent/fluent-bit:2.2.0 ${REGISTRY_URL}/fluent/fluent-bit:2.2.0
docker push ${REGISTRY_URL}/fluent/fluent-bit:2.2.0

docker pull docker.io/prom/node-exporter:v1.7.0
docker tag docker.io/prom/node-exporter:v1.7.0 ${REGISTRY_URL}/prom/node-exporter:v1.7.0
docker push ${REGISTRY_URL}/prom/node-exporter:v1.7.0

docker pull docker.io/prom/prometheus:v2.54.1
docker tag docker.io/prom/prometheus:v2.54.1 ${REGISTRY_URL}/prom/prometheus:v2.54.1
docker push ${REGISTRY_URL}/prom/prometheus:v2.54.1

docker pull docker.io/grafana/grafana:11.1.4
docker tag docker.io/grafana/grafana:11.1.4 ${REGISTRY_URL}/grafana/grafana:11.1.4
docker push ${REGISTRY_URL}/grafana/grafana:11.1.4

docker pull docker.io/library/ubuntu:20.04
docker tag docker.io/library/ubuntu:20.04 ${REGISTRY_URL}/library/ubuntu:20.04
docker push ${REGISTRY_URL}/library/ubuntu:20.04

docker pull docker.io/library/nginx:1.20.0
docker tag docker.io/library/nginx:1.20.0 ${REGISTRY_URL}/library/nginx:1.20.0
docker push ${REGISTRY_URL}/library/nginx:1.20.0

docker pull registry.k8s.io/sig-storage/nfs-subdir-external-provisioner:v4.0.2
docker tag registry.k8s.io/sig-storage/nfs-subdir-external-provisioner:v4.0.2 ${REGISTRY_URL}/sig-storage/nfs-subdir-external-provisioner:v4.0.2
docker push ${REGISTRY_URL}/sig-storage/nfs-subdir-external-provisioner:v4.0.2

docker pull docker.io/library/maven:3.5-jdk-8
docker tag docker.io/library/maven:3.5-jdk-8 ${REGISTRY_URL}/library/maven:3.5-jdk-8
docker push ${REGISTRY_URL}/library/maven:3.5-jdk-8

docker pull docker.io/library/node:12.22.4
docker tag docker.io/library/node:12.22.4 ${REGISTRY_URL}/library/node:12.22.4
docker push ${REGISTRY_URL}/library/node:12.22.4

docker pull cmd.cat/curl:latest
docker tag cmd.cat/curl ${REGISTRY_URL}/library/curl:latest
docker push ${REGISTRY_URL}/library/curl:latest

docker pull docker.io/library/mysql:5.7
docker tag docker.io/library/mysql:5.7 ${REGISTRY_URL}/library/mysql:5.7
docker push ${REGISTRY_URL}/library/mysql:5.7

docker pull docker.io/library/ubuntu:20.04
docker tag docker.io/library/ubuntu:20.04 ${REGISTRY_URL}/library/ubuntu:20.04
docker push ${REGISTRY_URL}/library/ubuntu:20.04

docker pull docker.io/library/python:3.7.13
docker tag docker.io/library/python:3.7.13 ${REGISTRY_URL}/library/python:3.7.13
docker push ${REGISTRY_URL}/library/python:3.7.13

docker pull docker.io/library/nginx:1.20.0
docker tag docker.io/library/nginx:1.20.0 ${REGISTRY_URL}/library/nginx:1.20.0
docker push ${REGISTRY_URL}/library/nginx:1.20.0

# infra
docker pull goharbor/harbor-exporter:v2.12.0
docker tag goharbor/harbor-exporter:v2.12.0 ${REGISTRY_URL}/goharbor/harbor-exporter:v2.12.0
docker push ${REGISTRY_URL}/goharbor/harbor-exporter:v2.12.0

docker pull goharbor/redis-photon:v2.12.0
docker tag goharbor/redis-photon:v2.12.0 ${REGISTRY_URL}/goharbor/redis-photon:v2.12.0
docker push ${REGISTRY_URL}/goharbor/redis-photon:v2.12.0

docker pull goharbor/harbor-db:v2.12.0
docker tag goharbor/harbor-db:v2.12.0 ${REGISTRY_URL}/goharbor/harbor-db:v2.12.0
docker push ${REGISTRY_URL}/goharbor/harbor-db:v2.12.0

docker pull goharbor/trivy-adapter-photon:v2.12.0
docker tag goharbor/trivy-adapter-photon:v2.12.0 ${REGISTRY_URL}/goharbor/trivy-adapter-photon:v2.12.0
docker push ${REGISTRY_URL}/goharbor/trivy-adapter-photon:v2.12.0

docker pull goharbor/registry-photon:v2.12.0
docker tag goharbor/registry-photon:v2.12.0 ${REGISTRY_URL}/goharbor/registry-photon:v2.12.0
docker push ${REGISTRY_URL}/goharbor/registry-photon:v2.12.0

docker pull goharbor/harbor-registryctl:v2.12.0
docker tag goharbor/harbor-registryctl:v2.12.0 ${REGISTRY_URL}/goharbor/harbor-registryctl:v2.12.0
docker push ${REGISTRY_URL}/goharbor/harbor-registryctl:v2.12.0

docker pull goharbor/harbor-jobservice:v2.12.0
docker tag goharbor/harbor-jobservice:v2.12.0 ${REGISTRY_URL}/goharbor/harbor-jobservice:v2.12.0
docker push ${REGISTRY_URL}/goharbor/harbor-jobservice:v2.12.0

docker pull goharbor/harbor-core:v2.12.0
docker tag goharbor/harbor-core:v2.12.0 ${REGISTRY_URL}/goharbor/harbor-core:v2.12.0
docker push ${REGISTRY_URL}/goharbor/harbor-core:v2.12.0

docker pull goharbor/harbor-portal:v2.12.0
docker tag goharbor/harbor-portal:v2.12.0 ${REGISTRY_URL}/goharbor/harbor-portal:v2.12.0
docker push ${REGISTRY_URL}/goharbor/harbor-portal:v2.12.0

docker pull goharbor/nginx-photon:v2.12.0
docker tag goharbor/nginx-photon:v2.12.0 ${REGISTRY_URL}/goharbor/nginx-photon:v2.12.0
docker push ${REGISTRY_URL}/goharbor/nginx-photon:v2.12.0

# enlin
docker pull registry.cn-hangzhou.aliyuncs.com/enlin/imgprocess:v1
docker tag registry.cn-hangzhou.aliyuncs.com/enlin/imgprocess:v1 ${REGISTRY_URL}/enlin/imgprocess:v1
docker push ${REGISTRY_URL}/enlin/imgprocess:v1

docker pull registry.cn-hangzhou.aliyuncs.com/enlin/ofrecord:v1
docker tag registry.cn-hangzhou.aliyuncs.com/enlin/ofrecord:v1 ${REGISTRY_URL}/enlin/ofrecord:v1
docker push ${REGISTRY_URL}/enlin/ofrecord:v1

docker pull registry.cn-hangzhou.aliyuncs.com/enlin/videosample:v1
docker tag registry.cn-hangzhou.aliyuncs.com/enlin/videosample:v1 ${REGISTRY_URL}/enlin/videosample:v1
docker push ${REGISTRY_URL}/enlin/videosample:v1

docker pull registry.cn-hangzhou.aliyuncs.com/enlin/dubhe-java:v1
docker tag registry.cn-hangzhou.aliyuncs.com/enlin/dubhe-java:v1 ${REGISTRY_URL}/enlin/dubhe-java:v1
docker push ${REGISTRY_URL}/enlin/dubhe-java:v1

docker pull registry.cn-hangzhou.aliyuncs.com/enlin/visual-server:v1
docker tag registry.cn-hangzhou.aliyuncs.com/enlin/visual-server:v1 ${REGISTRY_URL}/enlin/visual-server:v1
docker push ${REGISTRY_URL}/enlin/visual-server:v1

docker pull registry.cn-hangzhou.aliyuncs.com/enlin/model-converter:v1
docker tag registry.cn-hangzhou.aliyuncs.com/enlin/model-converter:v1 ${REGISTRY_URL}/enlin/model-converter:v1
docker push ${REGISTRY_URL}/enlin/model-converter:v1

docker pull registry.cn-hangzhou.aliyuncs.com/enlin/model-measuring:v1
docker tag registry.cn-hangzhou.aliyuncs.com/enlin/model-measuring:v1 ${REGISTRY_URL}/enlin/model-measuring:v1
docker push ${REGISTRY_URL}/enlin/model-measuring:v1

docker pull registry.cn-hangzhou.aliyuncs.com/enlin/automl-nas-pytorch17:v1
docker tag registry.cn-hangzhou.aliyuncs.com/enlin/automl-nas-pytorch17:v1 ${REGISTRY_URL}/enlin/automl-nas-pytorch17:v1
docker push ${REGISTRY_URL}/enlin/automl-nas-pytorch17:v1

docker pull registry.cn-hangzhou.aliyuncs.com/enlin/storage-init:v1
docker tag registry.cn-hangzhou.aliyuncs.com/enlin/storage-init:v1 ${REGISTRY_URL}/enlin/storage-init:v1
docker push ${REGISTRY_URL}/enlin/storage-init:v1

docker pull docker.io/dcm4che/slapd-dcm4chee:2.4.44-12.0
docker tag docker.io/dcm4che/slapd-dcm4chee:2.4.44-12.0 ${REGISTRY_URL}/dcm4che/slapd-dcm4chee:2.4.44-12.0
docker push ${REGISTRY_URL}/dcm4che/slapd-dcm4chee:2.4.44-12.0

docker pull docker.io/dcm4che/postgres-dcm4chee:10.0-12
docker tag docker.io/dcm4che/postgres-dcm4chee:10.0-12 ${REGISTRY_URL}/dcm4che/postgres-dcm4chee:10.0-12
docker push ${REGISTRY_URL}/dcm4che/postgres-dcm4chee:10.0-12

docker pull docker.io/dcm4che/dcm4chee-arc-psql:5.12.0
docker tag docker.io/dcm4che/dcm4chee-arc-psql:5.12.0 ${REGISTRY_URL}/dcm4che/dcm4chee-arc-psql:5.12.0
docker push ${REGISTRY_URL}/dcm4che/dcm4chee-arc-psql:5.12.0

docker pull registry.cn-hangzhou.aliyuncs.com/enlin/oneflow-gpu:base
docker tag registry.cn-hangzhou.aliyuncs.com/enlin/oneflow-gpu:base ${REGISTRY_URL}/enlin/oneflow-gpu:base
docker push ${REGISTRY_URL}/enlin/oneflow-gpu:base

docker pull registry.cn-hangzhou.aliyuncs.com/enlin/notebook:v1
docker tag registry.cn-hangzhou.aliyuncs.com/enlin/notebook:v1 ${REGISTRY_URL}/enlin/notebook:v1
docker push ${REGISTRY_URL}/enlin/notebook:v1

# harbor
docker pull docker.io/goharbor/harbor-exporter:v2.12.0
docker tag docker.io/goharbor/harbor-exporter:v2.12.0 ${REGISTRY_URL}/goharbor/harbor-exporter:v2.12.0
docker push ${REGISTRY_URL}/goharbor/harbor-exporter:v2.12.0

docker pull docker.io/goharbor/redis-photon:v2.12.0
docker tag docker.io/goharbor/redis-photon:v2.12.0 ${REGISTRY_URL}/goharbor/redis-photon:v2.12.0
docker push ${REGISTRY_URL}/goharbor/redis-photon:v2.12.0

docker pull docker.io/goharbor/harbor-db:v2.12.0
docker tag docker.io/goharbor/harbor-db:v2.12.0 ${REGISTRY_URL}/goharbor/harbor-db:v2.12.0
docker push ${REGISTRY_URL}/goharbor/harbor-db:v2.12.0

docker pull docker.io/goharbor/trivy-adapter-photon:v2.12.0
docker tag docker.io/goharbor/trivy-adapter-photon:v2.12.0 ${REGISTRY_URL}/goharbor/trivy-adapter-photon:v2.12.0
docker push ${REGISTRY_URL}/goharbor/trivy-adapter-photon:v2.12.0

docker pull docker.io/goharbor/registry-photon:v2.12.0
docker tag docker.io/goharbor/registry-photon:v2.12.0 ${REGISTRY_URL}/goharbor/registry-photon:v2.12.0
docker push ${REGISTRY_URL}/goharbor/registry-photon:v2.12.0

docker pull docker.io/goharbor/harbor-registryctl:v2.12.0
docker tag docker.io/goharbor/harbor-registryctl:v2.12.0 ${REGISTRY_URL}/goharbor/harbor-registryctl:v2.12.0
docker push ${REGISTRY_URL}/goharbor/harbor-registryctl:v2.12.0

docker pull docker.io/goharbor/harbor-jobservice:v2.12.0
docker tag docker.io/goharbor/harbor-jobservice:v2.12.0 ${REGISTRY_URL}/goharbor/harbor-jobservice:v2.12.0
docker push ${REGISTRY_URL}/goharbor/harbor-jobservice:v2.12.0

docker pull docker.io/goharbor/harbor-core:v2.12.0
docker tag docker.io/goharbor/harbor-core:v2.12.0 ${REGISTRY_URL}/goharbor/harbor-core:v2.12.0
docker push ${REGISTRY_URL}/goharbor/harbor-core:v2.12.0

docker pull docker.io/goharbor/harbor-portal:v2.12.0
docker tag docker.io/goharbor/harbor-portal:v2.12.0 ${REGISTRY_URL}/goharbor/harbor-portal:v2.12.0
docker push ${REGISTRY_URL}/goharbor/harbor-portal:v2.12.0

docker pull docker.io/goharbor/nginx-photon:v2.12.0
docker tag docker.io/goharbor/nginx-photon:v2.12.0 ${REGISTRY_URL}/goharbor/nginx-photon:v2.12.0
docker push ${REGISTRY_URL}/goharbor/nginx-photon:v2.12.0

pushd ./src
tar -zcf registry.tar.gz ./registry # | split -b 3900M -d -a 1 - registry.tar.gz.
split -b 3900M -d -a 1 registry.tar.gz registry.tar.gz.
sha256sum registry.tar.gz.* > registry.tar.gz.sha256
# sha256sum --check registry.tar.gz.sha256
# cat registry.tar.gz.{0..8} | tar -zxv -C /usr/local/src


pushd ./src
tar -zc ./registry | split -b 2000M -d -a 2 - /mnt/registry.tar.gz.

# cat /data/registry.tar.gz.* | tar -zxvf - -C /path/to/extract